home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 248 / 248.d81 / t.ml protocol < prev    next >
Text File  |  2022-08-26  |  7KB  |  404 lines

  1. u
  2.      AN ML PROGRAMMER'S GUIDE TO
  3.             DOTBASIC PLUS
  4.            by Dave Moorman
  5.  
  6.  
  7.     ML Coders UNITE! You have nothing
  8. to lose but your Chains!
  9.  
  10.     OK, maybe "chains" is too strong a
  11. term. But if you code in 65xx ML, you
  12. know how hard it is to even think in
  13. terms of relocatable code. Our ML
  14. likes absolute addresses. Which is not
  15. a particularly [bad] thing. I mean, we
  16. only have 65536 bytes to worry about!
  17.  
  18.     DotBASIC Plus is designed for
  19. those who have not become addicted
  20. with individual bits and bytes, but
  21. want plenty of power over the machine.
  22. And since DB+ is Adaptable to the
  23. needs of the programmer, we can
  24. provide infinite DB+ commands to do
  25. just that.
  26.  
  27.     But we have to follow a certain
  28. "protocol", a few rules that make DB+
  29. ML code "modulettes" work with each
  30. other and the system. So this article
  31. is about how to write a new DB+
  32. Command.
  33.  
  34.  
  35.  CHOOSING A NAME
  36.  ---------------
  37.  
  38.     Obviously, the command name has to
  39. be unique, a legal filename, no more
  40. than 9 characters, and
  41.  
  42.   not include any BASIC 2.0 Keyword!
  43.  
  44. (You won't believe my own frustration
  45. with command names like .PRINTSTR! The
  46. PRINT is tokenized by BASIC 2.0, and
  47. is not recognized by DotBASIC. Moan!)
  48.  
  49.     The filename for the code must be
  50.  
  51.  DCM.COMMAND.ML
  52.  
  53. where COMMAND is your Command name.
  54.  
  55.  
  56.  THE LAYOUT
  57.  ----------
  58.  
  59.     When a DB+ Command is called from
  60. the DB+ program, the Carry is Cleared.
  61. When the same command is called from
  62. another ML command, the Carry is Set.
  63. This allows us to sort out the two
  64. situations in just four bytes of code:
  65.  
  66.  0000 BCC BAS
  67.  0002 BCS ML
  68.  
  69.     Often, the difference between the
  70. two is that the BAS section will
  71. collect parameters from BASIC and put
  72. the values in various places. The ML
  73. portion expects the data to be in such
  74. places.
  75.  
  76.  BAS
  77.  **** JSR GETINT
  78.  **** STA 900
  79.  **** JSR GETINT
  80.  **** STA 901
  81.  
  82.  ML
  83.  **** LDA 900
  84.  **** LDX 901
  85.      etc
  86.  
  87.  BUT BACK TO THE HEADER
  88.  ----------------------
  89.  
  90.  0000 BCC BAS
  91.  0002 BCS ML
  92.  0004 BYT 255
  93.  0005 BYT ",S,Y,N,T,A,X",0
  94.  
  95.  ML
  96.  0006 RTS
  97.  
  98.  BAS
  99.  0007 ....
  100.  
  101.     Byte 4 of the code is the
  102. beginning of the ML's "include"
  103. section, which ends with a 255 byte.
  104. We will look at this in a moment.
  105.  
  106.     Next comes the "self-documenting"
  107. feature. In the above example, the
  108. text is added to the command name
  109. (when the DB+ programmer types SYS
  110. DD+6) as
  111.  
  112.  COMMAND,S,Y,N,T,A,X
  113.  
  114.     Your code at BAS will need to get
  115. the parameters into the code. We have
  116. some jumps to do this for you:
  117.  
  118.  DD = 14336
  119.  
  120.  GETINT   Gets Integer
  121.   Returns: LO>.A  HI>.X
  122.            (.Y not affected)
  123.  
  124.  GETFP    Gets Floating Point
  125.   Returns Floating Point in ACC#1
  126.  
  127.  GETSTR   Gets String
  128.   Returns: LEN>.A  LO>.X  HI>.Y
  129.  
  130.  GETSIN   Gets Signed Integer
  131.   Returns: LO>.A  HI>.X
  132.    Allows negative values.
  133.  
  134.  
  135.  DOING DATA
  136.  ----------
  137.  
  138.     You can put transitory data
  139. anywhere you think will be safe. I use
  140. the cassette buffer extensively for
  141. put and take situations. Obviously,
  142. this area is no good for values I want
  143. to keep from command call to command
  144. call.
  145.  
  146.     For this, you can set aside
  147. space in your code itself, using the
  148. following method:
  149.  
  150.  DD=14336
  151.  SETLOC = DD + 27
  152.  
  153.  TOP
  154.   BCC BAS
  155.   BCS ML
  156.   BYT 255
  157.   BYT",x,y",0
  158.  ML
  159.   RTS
  160.  DATA
  161.   BYT 0,0,0,0
  162.  BAS
  163.   LDA#DATA-TOP
  164.   LDX#164
  165.   JSR SETLOC
  166.  
  167.   JSR GETSIN
  168.   LDY#0
  169.   CLC
  170.   ADC(164),Y
  171.   STA(164),Y
  172.   INY
  173.   TXA
  174.   ADC(164),Y
  175.   STA(164),Y
  176.   JSR GETSIN
  177.   LDY#2
  178.   ADC(164),Y
  179.   STA(164),Y
  180.   INY
  181.   TXA
  182.   ADC(164),Y
  183.   STA(164),Y
  184.  
  185.     Here we set aside four bytes at
  186. DATA. To "find" where these bytes are,
  187. we first put the relative location of
  188. DATA (DATA-TOP) in .A, and a zero page
  189. address in .X. Then we use SETLOC,
  190. which finds the current address of the
  191. code and adds the distance to DATA.
  192. The result is put in 164/165, ready
  193. for Indirect Y addressing!
  194.  
  195.     And that is just what we do with
  196. each GETSIN -- adding the value to
  197. each byte in DATA. Later, we can use
  198. the same data to position a sprite or
  199. the cursor.
  200.  
  201.     But, you are saying, you have
  202. several commands that must access the
  203. same safe data. That certainly won't
  204. work with SETLOC. And you are right!
  205.  
  206.     So we have Data Blocks. These are
  207. small PRG files with enough space for
  208. the needed shared data. A Data Block
  209. filename uses a "#" to signify it is
  210. data and not a command. So use your
  211. assembler to create the Data Block
  212. file, with a name such as:
  213.  
  214.  DCM#MYDATA.ML
  215.  
  216.     In your code, you will need to
  217. include the Data Block.
  218.  
  219.  DD = 14336
  220.  SETDAT = DD + 30
  221.  
  222.   BCC BAS
  223.   BCS ML
  224.   BYT 1,"#MYDATA",0,255
  225.   BYT ",Q",0
  226.  
  227.  ML
  228.   RTS
  229.  
  230.  BAS
  231.   LDA#1  ; Index > .A
  232.   LDX#164; ZP > .X
  233.   JSR SETDAT
  234.  
  235.     The Data Block name (#MYPROG) is
  236. preceded by a number byte which serves
  237. as an index. The name is followed by a
  238. 0 byte and the "include" area is
  239. terminated with a 255 byte.
  240.  
  241.     To set the Data Block, the index
  242. number is put in .A and the zero page
  243. address is put in .X. JSR SETDAT then
  244. put the address of the Data Block in
  245. the two zero page bytes, ready for an
  246. Indirect Y call.
  247.  
  248.  
  249.  SUBROUTINES?
  250.  ------------
  251.  
  252.     If you absolutely need a
  253. subroutine in your code, you can use
  254. the SETLOC to put the subroutines
  255. address in two zero page bytes. Then
  256. poke a 76 in the byte before the zp
  257. address bytes. Simply JSR to that zp
  258. location.
  259.  
  260.  TOP
  261.   BCC BAS
  262.   BCS ML
  263.   BYT255
  264.   BYT0
  265.  ML
  266.   RTS
  267.  ROUTINE
  268.   LDA#0
  269.   SEC
  270.  LOOP
  271.   ROL
  272.   DEX
  273.   BPL LOOP
  274.   RTS
  275.  BAS
  276.   LDA#ROUTINE-TOP
  277.   LDX#165
  278.   JSR SETLOC
  279.   LDA#76
  280.   STA164
  281.  
  282.   JSR GETINT
  283.   AND#7
  284.   TAX
  285.   JSR 164
  286.  
  287.     This code uses a subroutine to set
  288. a given bit (bit number in .X). At
  289. BAS, we put the relative address of
  290. ROUTINE in .A and 165 in .X. The
  291. location of ROUTINE is put in 165/166
  292. by SETLOC. Then we put 76 in 164 (JMP
  293. instruction), and we are ready to
  294. roll!
  295.  
  296.  
  297.  COMMAND CALLING COMMAND
  298.  -----------------------
  299.  
  300.     But now for the niftiest trick of
  301. DB+ ML protocol. One command can call
  302. the ML portion of another command!
  303.  
  304.     Let's first write DCM.SETBIT.ML
  305.  
  306.  
  307.   BCC BAS
  308.   BCS ML
  309.   BYT255
  310.   BYT":ML BIT>900",0
  311.  BAS
  312.   RTS
  313.  ML
  314.   LDA#0
  315.   SEC
  316.   LDX 900
  317.  LOOP
  318.   ROL
  319.   DEX
  320.   BPL LOOP
  321.   RTS
  322.  
  323.     Simple enough. Now we will write
  324. DCM.SPR1.BC, which will turn on a
  325. given sprite.
  326.  
  327.  DD = 14336
  328.  SETML = DD + 21
  329.  DOML = DD + 24
  330.  
  331.   BCC BAS
  332.   BCS ML
  333.   BYT 1,"SETBIT",0,255
  334.   BYT ",BIT#",0
  335.  
  336.  ML
  337.   RTS
  338.  
  339.  BAS
  340.   LDA#1
  341.   JSR SETML
  342.   JSR GETINT
  343.   STA 900
  344.   JSR DOML
  345.   ORA 53269
  346.   STA 53269
  347.   RTS
  348.  
  349.     Note that in the include section,
  350. SETBIT does NOT have the preceding
  351. dot. I did this just to confuse
  352. myself! Again, the index number is put
  353. in .A then SETML is called. This sets
  354. up the jump to the code of SETBIT.
  355. Then any data can be set up for the
  356. routine (putting the bit number in
  357. 900) and the routine called with DOML.
  358.  
  359.  
  360.  SUMMARY
  361.  -------
  362.  
  363.     That's all there is to it. Do not
  364. jump directly to any location in your
  365. code. Do not load or store a register
  366. directly from or to any location in
  367. the body of your code. But you do have
  368. everything you need to put relative
  369. locations in zero page or find and use
  370. other command codes. Here is a
  371. schematic of the first bytes of your
  372. code:
  373.  
  374.  BCC BAS
  375.  BCS ML
  376.  BYT<index byte>
  377.  BYT<"com-name" or "#data-name">
  378.  BYT<0>
  379.  BYT<another index byte>
  380.  BYT<"com-name" or "#data-name">
  381.  BYT<0>
  382.  BYT 255    ; end include section
  383.  
  384.  BYT<"syntax info">
  385.  BYT 0
  386.  
  387.  Open space
  388.  
  389.  BAS
  390.   ...
  391.   RTS
  392.  
  393.  ML
  394.   ...
  395.   RTS
  396.  
  397.     I am looking forward to any an all
  398. DB+ Commands you might think of. I
  399. believe anything we can do in ML can
  400. become available to DB+ users!
  401.  
  402.  DMM
  403.  
  404.  
  405.